<?
//yunUploadSt = 0 没有上传
//yunUploadSt = 2 上传中
//yunUploadSt = 1 上传完毕
$bucket = 'resmandata';
header("Content-type: text/html; charset=utf-8");
require('../configs/config.php');
require('../lib/mySQL.php');
require 'sdk.class.php';
$uploadMinSize = 100000000; //100m;
$DB = new DB;
$DB->info['host'] = $CONF['db_host'];
$DB->info['usr']  = $CONF['db_user'];
$DB->info['pwd']  = $CONF['db_pass'];
$DB->info['db']   = $CONF['db_db'];
$DB->db_connect();
mysql_query("set names utf8");
$r = $DB->db_query_first("select id,path,fileTypeId from res_file where yunUploadSt=0 and size > ".$uploadMinSize." and isDel=0 and isPost=1 order by id");
if($r && $r['path']) //上传
{
	//echo basename($r['path']);
	/**
	 * 加载sdk包以及错误代码包
	 */
	$oss_sdk_service = new ALIOSS();
	$DB->db_query("update res_file set yunUploadSt='2',yunUploadSTime='".date("Y-m-d H:i:s")."' where id=".$r['id']);
	//设置是否打开curl调试模式
	$oss_sdk_service->set_debug_mode(TRUE);
	try{
		if($r['fileTypeId']==39)
		{
			$r['path'] = str_replace("s.",".",$r['path']);
		}
		$fname = basename($r['path']);
		echo "file id=".$r['id']." file path=".$r['path']."<br/>";
	 	upload_by_multi_part($oss_sdk_service,$fname,"../".$r['path']);
	 	$DB->db_query("update res_file set yunDownUrl='http://resmandata.oss-cn-qingdao.aliyuncs.com/".$fname."',yunUploadSt='1',yunUploadETime='".date("Y-m-d H:i:s")."' where id=".$r['id']);
	}catch (Exception $ex){
	    $DB->db_query("update res_file set yunUploadSt='0' where id=".$r['id']);
		die($ex->getMessage());
	}
}
else
{
	echo "no file to upload";
}
//通过multipart上传文件
function upload_by_multi_part($obj,$objName,$filePath){
	global $bucket;
	$object = $objName;  //英文
	$filepath = $filePath;  //英文
	$options = array(
		ALIOSS::OSS_FILE_UPLOAD => $filepath,
		'partSize' => 5242880,
	);
	$response = $obj->create_mpu_object($bucket, $object,$options);
}
?>